package com.interview.controller;


import com.interview.pojo.Catalogue;
import com.interview.service.CatalogueService;
import com.interview.utils.Id_Builder;
import com.interview.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/catalogue")
public class CatalogueController {

    @Resource(name ="CatalogueServiceImpl" )
    private CatalogueService catalogueService;

    @PostMapping
    public void add(@RequestBody Catalogue catalogue){

        catalogue.setId(Id_Builder.nextId());
        catalogue.setCatalogue_size(0);

        catalogueService.add(catalogue);
    }
    //删除文章
    //http://localhost:10087/catalogue

    @PostMapping("/del")
    public void del(@RequestBody Catalogue catalogue){

        catalogueService.del(catalogue);
    }

    @PostMapping("/up")
    public void up(@RequestBody  Catalogue catalogue) {
        catalogueService.up(catalogue);
    }


    // 获取 指定大方向 下的 所有目录

    //http://localhost:10087/catalogue
    @GetMapping
    public Result<List<Catalogue>> queryAll(String titleId){
        System.out.println("titleID  : "+ titleId);
        Catalogue catalogue =new Catalogue();
        catalogue.setTitle_id(titleId);
        List<Catalogue> query = catalogueService.query(catalogue);
        System.out.println("-----"+query);
        return new Result<List<Catalogue>>(true,2000,"查询成功",query );
    }


    //http://localhost:10087/catalogue/all
    //获取全部标签
    @GetMapping("/all")
    public Result<List<Catalogue>> query_select_all(){

        List<Catalogue> query = catalogueService.queryAll();
        return new Result<List<Catalogue>>(true,2000,"查询成功",query );
    }


    //查询全部数量
    //http://localhost:10087/catalogue/count
    @GetMapping("/count")
    public int count(){
        int i = catalogueService.catalogue_count_all();
        return i;
    }



    //获取全部标签
    @GetMapping("/queryID")
    public Result<Catalogue> queryID(  String catalogueId){

        Catalogue query = catalogueService.queryID(catalogueId);
        return new Result<Catalogue>(true,2000,"查询成功",query );
    }



}
